package com.spring.demo6.eg1;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author vhans
 */
public class InjectTest {
    @Test
    public void test0() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig0.class);
        for (String beanName : context.getBeanDefinitionNames()) {
            // 当Service2中的构造函数或者字段service1加上@Autowired注解后，Service1注入到Service2中
            System.out.println(beanName + "->" + context.getBean(beanName));
        }
    }

    @Test
    public void test1() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig1.class);
        for (String beanName : context.getBeanDefinitionNames()) {
            // 当Service3中的方法上加上@Autowired注解后，Service1注入到Service3中
            System.out.println(beanName + "->" + context.getBean(beanName));
        }
    }

    @Test
    public void test2() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig2.class);
        for (String beanName : context.getBeanDefinitionNames()) {
            // 当Service4中的set方法上加上@Autowired注解后，Service1注入到Service4中
            System.out.println(beanName + "->" + context.getBean(beanName));
        }
    }

    @Test
    public void test3() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig3.class);
        for (String beanName : context.getBeanDefinitionNames()) {
            System.out.println(beanName + "->" + context.getBean(beanName));
        }
    }
}
